﻿using System;
using System.Linq.Expressions;
using System.Collections.Generic;

namespace PMngr.Main
{
    public class ItemModel
    {
        public static readonly IDictionary<string, string> Dict = new Dictionary<string, string>
           {
               {"Code", "Code"},
               {"Name", "选项名称"},
               {"Order", "选项顺序"},
               {"IsValid", "是否有效"},
               {"Description", "选项描述"},
               {"Type", "Type"}              
           };

        public int Code { get; set; }
        public string Name { get; set; }
        public int Order { get; set; }
        public bool IsValid { get; set; }
        public string Description { get; set; }
        public string Type { get; set; }

        // get property native name
        [System.Diagnostics.DebuggerStepThrough]
        public static string GetPropertyName<T>(Expression<Func<ItemModel, T>> func)
        {
            return GetPropertyImpl(func);
        }
        // get property friendly name
        [System.Diagnostics.DebuggerStepThrough]
        public static string GetFriendlyName<T>(Expression<Func<ItemModel, T>> func)
        {
            var name = GetPropertyImpl(func);
            return name != null ? Dict[name] : null;
        }
        [System.Diagnostics.DebuggerStepThrough]
        private static string GetPropertyImpl(LambdaExpression expression)
        {
            var member = expression.Body as MemberExpression;
            return member != null ? member.Member.Name : null;
        }

    }
}
